package ddemo.viewAndcontroller;

import ddemo.pojo.Interface;
import ddemo.pojo.User;
import ddemo.service.AskService;
import ddemo.service.InterfaceService;

import java.util.Scanner;

public class menuView {

    public static void chooseMnue(User user) {
    if (user.getPower() == 1) {
        Mnue1(user);
    }
    if (user.getPower() == 3) {
        Mnue3(user);
    }
    if (user.getPower() == 2) {
        Mnue2(user);
    }
}
 public static void Mnue1(User user){
    while(true){

        System.out.println("Welcome " + user.getUsername() + "同学");
        while("0".equals(user.getEv())) {
            System.out.println("您还未绑定您的电动车信息,请完善您的电动车信息");
            user.setEv(ddcView.Ddc(user));
            System.out.println(user.getEv());
        }

        System.out.println("您的电动车车牌号是:"+user.getEv());
        System.out.println("您要选择的操作是：");
        System.out.println("1.您的电动车还未上牌,无法充电");
        System.out.println("2.停车");
        System.out.println("3.电动车上牌");
        System.out.println("4.退出程序");
        String mnuenum=new Scanner(System.in).next();
        if("1".equals(mnuenum)){
            //Chongdian(user);
        }
        else if("2".equals(mnuenum)){
            parkView.park(user);
        }
        else if("3".equals(mnuenum)){
            System.out.println("已申请上牌");
            System.out.println("------------------------------------------------");
            AskService.ask(user);
        }
        else if("4".equals(mnuenum)){
            return;
        }
        else{
            System.out.println("输入错误，请输入正确的数字");
            System.out.println("--------------------------------");
            mnuenum=new Scanner(System.in).next();
        }
    }

}
    private static void Mnue2(User user) {
        while(true){
            System.out.println("Welcome " + user.getUsername() + "同学");
            System.out.println("您的电动车车牌号是:"+user.getEv());
            System.out.println("您要选择的操作是：");
            System.out.println("1.充电");
            System.out.println("2.停车");
            System.out.println("3.预约");
            System.out.println("4.退出程序");
            System.out.println("--------------------------------");
            String mnuenum=new Scanner(System.in).next();
            if("1".equals(mnuenum)){
                Interface i=new Interface();
                i= InterfaceService.isChongdian(user);
                if(null==i)
                {
                chongdianView.Chongdian(user);
                }
                else{
                    System.out.println("您已选择充电桩,是否停止使用");
                    System.out.println("1.停止使用");
                    System.out.println("2.回到上一级");
                    System.out.println("--------------------------------");
                    String num=new Scanner(System.in).next();
                    if("1".equals(num)){
                      InterfaceService.stopUse(i.getId());
                        System.out.println("已停止使用");
                        System.out.println("--------------------------------");
                    }
                    else if("2".equals(num)){
                       ;
                    }
                    else{
                        System.out.println("输入错误，请输入正确的数字");
                        System.out.println("--------------------");
                    }
                }

            }
            else if("2".equals(mnuenum)){
                parkView.park(user);
            }
            else if("3".equals(mnuenum)){

                    bookingView.choose(user);
            }
            else if("4".equals(mnuenum)){
                return;
            }
            else{
                System.out.println("输入错误，请输入正确的数字");
                System.out.println("--------------------");
            }
        }

    }
    public static void Mnue3(User user){
        System.out.println("Welcome " + user.getUsername() +"同学"+ ","+"您是本站的管理员");
        while("0".equals(user.getEv())) {
            System.out.println("您还未绑定您的电动车信息,请完善您的电动车信息");
            user.setEv(ddcView.Ddc(user));
            System.out.println(user.getEv());
            System.out.println("————————————————");
            System.out.println("————————————————");
        }
        while(true){

            System.out.println("Welcome " + user.getUsername() + "同学");
            System.out.println("您的电动车车牌号是:"+user.getEv());
            System.out.println("您要选择的操作是：");
            System.out.println("1.充电");
            System.out.println("2.停车");
            System.out.println("3.充电站管理");
            System.out.println("4.停车场管理");
            System.out.println("5.申请上牌");
            System.out.println("6.预约管理");
            System.out.println("7.退出程序");
            System.out.println("————————————————");
            System.out.println("————————————————");
            String mnuenum=new Scanner(System.in).next();
            switch (mnuenum){
                case "1":
                    chongdianView.Chongdian(user);
                    break;
                case "2":
                    break;
                case "3":
                    manageView.chargerManage();
                    break;
                case "4":
                    manageView.parkManage();
                    break;
                case "5":
                    manageView.shangpai();
                    break;
                case "6":
                   choosebookManage();
                    break;
                case "7":
                    return;
                default:
                    System.out.println("错误输出请重试");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

            }
        }

    }

    private static void choosebookManage() {
        System.out.println("------------------------");
        System.out.println("请选择您操作");
        System.out.println("1.充电预约管理");
        System.out.println("2.停车预约管理");
        System.out.println("------------------------");
        String mnuenum=new Scanner(System.in).next();
        switch (mnuenum){
            case "1":
                manageView.chargerBookManager();
                break;
            case "2":
                break;
            default:
                System.out.println("错误输出请重试");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

        }
    }


}
